package com.ziJing.multithreading.sync.t_06_StopThread;

/**
 * @author zhangbo
 * @program: Multithreading
 * @ClassName StopThreadDemo
 * @description: $
 * @date 2023-02-05 14:50:49
 */
public class StopThreadDemo {
    private volatile static Boolean stop = false;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (!stop) {
                //do some thing...
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("go...");
            }
            System.out.println("end.....");
            Thread.interrupted();
        });


        t1.start();
        Thread.sleep(1000);
        stop = true;
    }
}
